/*
 * Copyright 2016 drakeet. https://github.com/drakeet
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.epfresh.adapter;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.epfresh.R;
import com.epfresh.activity.DetailGoodsActivity;
import com.epfresh.activity.HomeActivity;
import com.epfresh.activity.*;
import com.epfresh.api.utils.FileUtil;
import com.epfresh.global.DataManager;
import multitype.ItemViewBinder;
import com.epfresh.fragment.*;
import com.epfresh.bean.*;
import com.umeng.analytics.MobclickAgent;

public class ViewBinderHomeOftenTitle
        extends ItemViewBinder<OftenTitle, ViewBinderHomeOftenTitle.ViewHolder> implements View.OnClickListener{

    public final static double OFTENHAVE = 0.2;
    public final static double OFTENNO = 0.1;

//    public TopFragmentRecycler context;
    public HomeFragmentNew context;


    @NonNull @Override
    protected ViewHolder onCreateViewHolder(
            @NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View view = inflater.inflate(R.layout.include_home_often_title, parent, false);
        return new ViewHolder(view);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_home_often_go:
                MobclickAgent.onEvent(context.getAppActivity(),"Click_Home_AccountSettle");
                ((HomeActivity)context.getAppActivity()).onTabSelect(1);
                break;
            case R.id.tv_home_often_goods:
//                ((HomeFragmentNew)context.getAppActivity()).onTabSelect(1);
                break;
        }

    }


    @Override
    protected void onBindViewHolder(@NonNull final ViewHolder holder, @NonNull OftenTitle category) {
        holder.tv_home_often_go.setOnClickListener(this);
        holder.tv_home_often_ask.setOnClickListener(this);
        holder.tv_home_often_goods.setOnClickListener(this);
        holder.rl_often_no.setVisibility(View.GONE);
        if (category.getHaveMore()==OFTENHAVE){
            holder.rl_often_no.setVisibility(View.GONE);
        }else{
            holder.rl_often_no.setVisibility(View.VISIBLE);
        }

/*        if (category.isHasAsk()){
            holder.tv_home_often_ask.setVisibility(View.VISIBLE);
            holder.v_home_often_title_line.setVisibility(View.VISIBLE);
        }else{
            holder.tv_home_often_ask.setVisibility(View.VISIBLE);
            holder.v_home_often_title_line.setVisibility(View.VISIBLE);
        }*/

        if (category.isHasRedRound()){
            holder.iv_red_round.setVisibility(View.VISIBLE);
        }else{
            holder.iv_red_round.setVisibility(View.GONE);
        }

/*        SharedPreferences sp = FileUtil.getSharedPreferences();
        if(sp.getInt("oftenNewFlag",0)==0){
            holder.tv_home_often_tip.setVisibility(View.VISIBLE);
            SharedPreferences.Editor edit = sp.edit();
            edit.putInt("oftenNewFlag", 1);
            edit.commit();
            holder.tv_home_often_tip.postDelayed(new Runnable() {
                public void run() {
                    holder.tv_home_often_tip.setVisibility(View.GONE);
                }
            }, 5000);
        }*/
    }


    static class ViewHolder extends RecyclerView.ViewHolder {
        View iv_home_often_refresh,iv_home_often_title,tv_home_often_go,tv_home_often_ask,v_home_often_title_line,iv_red_round,tv_home_often_goods,rl_often_no,tv_home_often_tip;
        ViewHolder(@NonNull View itemView) {
            super(itemView);
            //iv_home_often_title = itemView.findViewById(R.id.iv_home_often_title);
            //iv_home_often_refresh  = itemView.findViewById(R.id.iv_home_often_refresh);
            tv_home_often_tip = itemView.findViewById(R.id.tv_home_often_tip);
            tv_home_often_go = itemView.findViewById(R.id.tv_home_often_go);
            tv_home_often_ask = itemView.findViewById(R.id.tv_home_often_ask);
            tv_home_often_goods = itemView.findViewById(R.id.tv_home_often_goods);
            rl_often_no = itemView.findViewById(R.id.rl_often_no);

            v_home_often_title_line = itemView.findViewById(R.id.v_home_often_title_line);
            iv_red_round = itemView.findViewById(R.id.iv_red_round);


        }
    }
}
